package gaml.testing;

import static org.junit.Assert.assertEquals;
import gaml.error.GamlException;
import gaml.text.TextNodeBridge;
import gaml.text.YamlParserStore;
import gaml.text.YamlText;
import gaml.text.parser.AliasNodeParser;
import gaml.text.parser.MappingNodeParser;
import gaml.text.parser.ScalarNodeParser;
import gaml.yaml.YamlNode;
import gaml.yaml.ahchor.YamlAnchorCodeStore;

import org.junit.Test;


public class AliasNodeParserTest {
	static final String sampleText = "&mapanch ?mapkey1: >scal1 #alias test mapping\n?mapkey2: &scalanch >scal2\n?mapkey3: >scal3\n?mapkey4: *scalanch\n?mapkey5: >scal5";

	@Test
	public void testParseText () throws GamlException {
		YamlText text = new YamlText ().read (sampleText);
		
		YamlAnchorCodeStore anchors = new YamlAnchorCodeStore ();
		YamlParserStore store = new YamlParserStore (new ScalarNodeParser (anchors));
		store.register (new MappingNodeParser (anchors, store));
		store.register (new AliasNodeParser (anchors));
		
		YamlNode res = new TextNodeBridge (text, null).parseText (store).getNode ();
//		System.out.println (res.getMapChildren ().get ("mapkey4").getAnchor ().getCode ());
		
		assertEquals (res.getMappingChildren ().get ("mapkey2"), res.getMappingChildren ().get ("mapkey4").getAnchor ().getNode ());
	}
}
